package ecrans;

import java.awt.BorderLayout;
import java.awt.Cursor;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.LayoutStyle.ComponentPlacement;

import util.BrowserControl;

import java.awt.Font;
import java.awt.Toolkit;

/**
 * Ecran A propos contenant des informations sur le projet
 *
 * @author Christophe Schutz
 *
 */
@SuppressWarnings("serial")
public class EcranAPropos extends JDialog {

	private final JPanel contentPanel = new JPanel();

	/**
	 * Create the dialog.
	 */
	public EcranAPropos() {
		setTitle("A propos");
		setIconImage(Toolkit.getDefaultToolkit().getImage("ressources\\images\\saturn.png"));
		setModal(true);
		setBounds(100, 100, 426, 208);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		
		JLabel lblComicsphere = new JLabel("<html><u>Comicsphere</u></html>");
		lblComicsphere.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent arg0) {
				setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			}
			@Override
			public void mouseExited(MouseEvent arg0) {
				setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			}
			@Override
			public void mousePressed(MouseEvent arg0) {
				lblComicsphereMousePressed();
			}
		});
		lblComicsphere.setFont(new Font("Lucida Grande", Font.PLAIN, 12));
		
		JLabel lblCopyright = new JLabel("(c) 2011");
		lblCopyright.setFont(new Font("Lucida Grande", Font.PLAIN, 12));
		
		ImageIcon logo = new ImageIcon("ressources/images/logo.png");
		
		JButton btnOk = new JButton("OK");
		btnOk.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				btnOkActionPerformed();
			}
		});
		
		JLabel lblLogo = new JLabel(logo);
		
		JLabel lblDescription = new JLabel("<html>ComicSphere est un projet r\u00E9alis\u00E9 dans le cadre de la licence professionnelle CDED \u00E0 l'IUT Illkirch par 7 \u00E9tudiants.</html>");
		lblDescription.setFont(new Font("Lucida Grande", Font.PLAIN, 12));
		
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addContainerGap()
							.addComponent(lblLogo))
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGap(125)
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(lblDescription)
								.addGroup(gl_contentPanel.createSequentialGroup()
									.addComponent(lblComicsphere, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(lblCopyright)))))
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap(227, Short.MAX_VALUE)
					.addComponent(btnOk, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE)
					.addGap(90))
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addContainerGap()
							.addComponent(lblLogo))
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGap(24)
							.addComponent(lblDescription, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblComicsphere)
						.addComponent(lblCopyright))
					.addGap(9)
					.addComponent(btnOk)
					.addContainerGap())
		);
		contentPanel.setLayout(gl_contentPanel);
	}
	
	public void btnOkActionPerformed() {
		this.dispose();
	}
	
	public void lblComicsphereMousePressed() {
		BrowserControl.displayURL("http://130.79.81.48/");
	}
}
